<template>
  <div class="app-container">
    <el-card v-if="activeTab == 'userinfo'">
      <div slot="header" class="clearfix">
        <span>基本资料</span>
      </div>
      <userInfo
        :user="user"
        @changeTab="
          (e) => {
            this.activeTab = e;
          }
        "
      />
    </el-card>
    <el-card v-if="activeTab == 'password'">
      <div slot="header" class="clearfix">
        <span>修改密码</span>
      </div>
      <resetPwd
        :propUser="user"
        @changeTab="
          (e) => {
            this.activeTab = e;
          }
        "
      />
    </el-card>
    <el-card v-if="activeTab == 'phoneNumber'">
      <div slot="header" class="clearfix">
        <span>修改账号</span>
      </div>
      <resetPhone :propUser="user" @changeTab="resetPhone_changeTab" />
    </el-card>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import resetPhone from "./resetPhone";
import { getUserProfile, updateUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd, resetPhone },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
    };
  },
  created() {
    this.getUser();
  },

  methods: {
    resetPhone_changeTab(e) {
      this.activeTab = e;
      this.getUser();
    },
    getUser() {
      getUserProfile().then((response) => {
        console.log(response);
        this.user = response.data;
        this.user.schoolPostList = response.schoolPostList ? response.schoolPostList : [];
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
  },
};
</script>
